package com.guess.lolguessing.service.impl;

import ch.qos.logback.core.LogbackException;
import com.guess.lolguessing.context.BaseContext;
import com.guess.lolguessing.domain.dto.UserLoginDTO;
import com.guess.lolguessing.domain.po.KpUser;
import com.guess.lolguessing.exception.LoginFailedException;
import com.guess.lolguessing.mapper.KpUserMapper;
import com.guess.lolguessing.service.IKpUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-10-16
 */
@Service
public class KpUserServiceImpl extends ServiceImpl<KpUserMapper, KpUser> implements IKpUserService {


    public KpUser userLogin(UserLoginDTO dto) {
        KpUser one = this.lambdaQuery().eq(KpUser::getUsername, dto.getUsername()).one();

        if(one == null) {
            throw new LoginFailedException("账号不存在");
        }
        if(!one.getPassword().equals(dto.getPassword())) {
            throw new LoginFailedException("账号密码不正确");
        }
        return one;
    }

    public String getUsernameById(Integer userId) {
        KpUser one = this.lambdaQuery().eq(KpUser::getId, userId).one();
        return one.getUsername();
    }
}
